JQuery Validation dates [migrated]
Posted
by
james
on Programmers
See other posts from Programmers
or by james
Published on 2011-11-23T16:22:16Z
Indexed on
2011/11/23
18:03 UTC
Read the original article
Hit count: 228
jQuery
Im trying to get my form to validate...so basically its working, but a little bit too well, I have two text boxes, one is a start date, the other an end date in the format of mm/dd/yyyy
if the start date is greater than the end date...there is an error
if the end date is less than the start date...there is an error
if the start date is less than today's date...there is an error
The only thing is when I correct the error, the error warning is still there...here is my code:
// Validate Date Ranges
if ($(this).val() != '' && dates.not(this).val != '') {
if ($(this).hasClass("FromCal")) {
if (new Date(testDate) > new Date(otherDate)) {
addError($(this));
$('.flightDateError').text('* Start date must be earlier than end date.');
isValid = false;
return;
}
}
else {
if (new Date(testDate) < new Date(otherDate)) {
addError($(this));
$('.flightDateError').text('* End date must be later than start date.');
return;
}
}
}
and here are the two text boxes:
<div id="campaign_start" style="display: inline-block">
<label class="date_range_label">from:</label>
<asp:TextBox ID="FromCalTbx" runat="server" Width="100px" CssClass="FromCal editable float_left required" />
</div>
<div id="campaign_end" style="display: inline-block">
<label class="date_range_label">to:</label>
<asp:TextBox ID="ToCalTbx" runat="server" Width="100px" CssClass="float_left optional"/>
</div>
PS -
testDate is the start Date
otherDate is the end Date
© Programmers or respective owner